<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./vue.global.js"></script>
</head>
<body>
    <div id="app">
        <!--        父传子1:子组件定义-->
        <my-head title="hello world" :count="count"></my-head>
    </div>
    <script>
        let app = Vue.createApp({
            data(){
                return {
                    count: 10
                }
            },
            mounted(){
                setTimeout(()=>{
                    this.count = 20
                },2000)
            },
        })

        app.component(
            'MyHead',
            {
                //父传子2:子组件定义变量count Number类型
                props:{
                  'count':{
                      type:Number
                  }
                },
                // props:['title','count'],
                data(){
                  return {
                      //定义变量接受headCount接受父组件count，可以改变自己组件变量
                      headCount: this.count
                  }
                },
                template: `
                <header>
                  <!--父传子3:子组件使用变量-->
                  <div>父组件传递过来的：title:{{title}} . 父组件count：{{count}} , 子组件headCount：{{headCount}}</div>
                    <h2>logo</h2>
                    <ul>
                        <li>首页</li>
                        <li>视频</li>
                        <li>音乐</li>
                    </ul>
                </header>
                `,
                mounted() {
                    setTimeout(()=>{
                        //默认父组件传递来的值是只读的
                        this.count = 4000;
                        //子组件值可以修改
                        this.headCount = 4000;
                    },4000)
                }
            })

        let vm = app.mount('#app');
    </script>

</body>
</html>